/* 
 * File:   vfs.h
 * Author: PprrATeekK
 *
 * Created on October 10, 2012, 4:32 PM
 */

#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include <stdlib.h>
#include "vfs_errorcodes.h"

#pragma once
#ifndef vfs_H
#define vfs_H

/*/////////////////////////////////////////////////////////////////////////////
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~//Constants//~~~~~~~~~~~~~~~~~~~~~~~~~~~
////////////////////////////////////////////////////////////////////////////*/

# define createvfs_SUCCESS 0
# define createvfs_FAILURE 1
# define mountvfs_SUCCESS 0
# define mountvfs_FAILURE 1
# define unmountvfs_SUCCESS 0
# define unmountvfs_FAILURE 1
# define Block_EMPTY 1
# define Block_FULL 0
# define mounted 1
#define unMounted 0

#define fileNameLength 260
#define fileSystemNameLength 100
#define bufferSize 1024
#define addressLength 500

typedef struct blocks {
    int empty;
} Block;

// File Descriptor Structure //
typedef struct FileDescriptor {
    char name[fileNameLength];              //Name of File / Directory
    char address[addressLength];          // Address of File/Directory in directory structure / nary Tree.
    long size;                  // Size of file
    long startBlock;            //Offset of buffer Block where file is stored in VFS.
    char type;                  // Type > File / Directory / Empty
} FileDescriptor;

// Structure representing buffer Block in VFS //
typedef struct buffer {
    char buff[bufferSize];            //Size of one Block = 1024 Bytes = 1 KB.
} buffer;




/*/////////////////////////////////////////////////////////////////////////////
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~//Variables//~~~~~~~~~~~~~~~~~~~~~~~~~~~
////////////////////////////////////////////////////////////////////////////*/

int noOfFiles;  // Same as no. of Blocks, can be used as no. of files written to VFS till now
int fileSystemSize;   // Size of VFS file
char fileSystemName[fileSystemNameLength];
int noOfBuffers;
int noOfFileDescriptors;
int noOfFreeBlockListItems;
int fileSize;  // size of 1 file, in terms of no. of buffer blocks
long fileDescOffset;
long bufferOffset;
long blockOffset;

int mountStatus;

/*/////////////////////////////////////////////////////////////////////////////
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~//Function Prototypes//~~~~~~~~~~~~~~~~~~~~~~~~~~~
////////////////////////////////////////////////////////////////////////////*/

int mount(char* fileSystemName);
int unMount();
int creatVFS(int fileSystemSize, char * fileSystemName);
int invalidChar(char * name,int mode);

#endif
